/**
 * 配置文件
 */

 const defaultSettings = {

  // debug
  logPeriod: 1,          // 终端输出频率 单位s
  // graphics
  backgroundColor:0x1982cc,
  useRandomMaterial: true,

  // physics
  gravityConstant: -9.8,
  airDensityConstant: 0.4,
  margin:0.05,

}

const allSettings = {};

class A3Settings {
  
  constructor(){

    this.set( defaultSettings );

  }

  set ( settings ) {

    // this.clear();  // 需要删除旧配置时 取消注释
    
    for( var key in settings ) {

      allSettings[key] = settings[key];

    }

    this.update();

  }

  clear( ) {

    for( var key in allSettings ) {

      delete A3Settings.prototype[key];
      delete allSettings[key];

    }

  }

  update() {
    
    for( var key in allSettings ) {

      A3Settings.prototype[key] = {
        get( ) {
          return allSettings[key];
        },
      
        set( val ) {
          allSettings[key] = val;
          return allSettings[key];
        }
      }

    }

  }

  setValue( key, value ) {

    if( key in allSettings ) {
      allSettings[key] = value;
    }

    return allSettings[key];
    
  }

}

const settings = new A3Settings();

export default settings;
